package com.rchat.pocmini.activity.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.rchat.pocmini.R;
import com.rchat.pocmini.account.PocAccount;
import com.rchat.pocmini.activity.bean.FriendBean;
import com.rchat.pocmini.util.HttpUtil;

import java.io.IOException;
import java.util.ArrayList;

/**
 * Created by ljd on 2017/3/10.
 */

public class FriendListViewAdapter extends BaseAdapter {

    private ArrayList<FriendBean> data;
    private LayoutInflater inflater;

    public FriendListViewAdapter(Context context, ArrayList<FriendBean> data) {
        this.data = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (null == convertView) {
            convertView = inflater.inflate(R.layout.friend_list_view_item_layout, null);
            holder = new ViewHolder();
            holder.ivAvatar = (ImageView) convertView.findViewById(R.id.iv_avatar);
            holder.tvName = (TextView) convertView.findViewById(R.id.tv_name);
            holder.tvId = (TextView) convertView.findViewById(R.id.tv_id);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final FriendBean bean = data.get(position);
        holder.tvName.setText(bean.getName());
        holder.tvId.setText(bean.getId());

        return convertView;
    }

    private static class ViewHolder {
        private ImageView ivAvatar;
        private TextView tvName;
        private TextView tvId;
    }


}
